admin: Add --karg-proc-cmdline argument
authorColin Walters <walters@verbum.org>
Mon, 13 Jan 2014 13:45:56 +0000 (08:45 -0500)
committerColin Walters <walters@verbum.org>
Wed, 15 Jan 2014 14:19:32 +0000 (09:19 -0500)
When installing a new tree inside an existing OS, this is a convenient
way to include the command line arguments one needs (such as root=).

src/ostree/ot-admin-builtin-deploy.c
tests/test-admin-deploy-karg.sh

index 54e34856a860b7200c3c7fcf2acfc489e2b20787..9d47924922e3e0ea0c4144dd427bb4fcd8e518b2 100644 (file)
@@ -32,6 +32,7 @@
 static gboolean opt_no_bootloader;
 static gboolean opt_retain;
 static char **opt_kernel_argv;
+static gboolean opt_kernel_proc_cmdline;
 static char *opt_osname;
 static char *opt_origin_path;
 
@@ -40,6 +41,7 @@ static GOptionEntry options[] = {
   { "origin-file", 0, 0, G_OPTION_ARG_FILENAME, &opt_origin_path, "Specify origin file", NULL },
   { "no-bootloader", 0, 0, G_OPTION_ARG_NONE, &opt_no_bootloader, "Don't update bootloader", NULL },
   { "retain", 0, 0, G_OPTION_ARG_NONE, &opt_retain, "Do not delete previous deployment", NULL },
+  { "karg-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_proc_cmdline, "Import current /proc/cmdline", NULL },
   { "karg", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv, "Set kernel argument, like --karg=root=/dev/sda1", NULL },
   { NULL }
 };
@@ -56,6 +58,7 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancell
   gs_unref_object OstreeDeployment *new_deployment = NULL;
   gs_unref_object OstreeDeployment *merge_deployment = NULL;
   gs_free char *revision = NULL;
+  gs_unref_ptrarray GPtrArray *kargs = NULL;
 
   context = g_option_context_new ("REFSPEC - Checkout revision REFSPEC as the new default deployment");
 
@@ -118,9 +121,48 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancell
       goto out;
     }
 
+  kargs = g_ptr_array_new_with_free_func (g_free);
+
+  if (opt_kernel_proc_cmdline)
+    {
+      gs_unref_object GFile *proc_cmdline_path = g_file_new_for_path ("/proc/cmdline");
+      gs_free char *proc_cmdline = NULL;
+      gsize proc_cmdline_len = 0;
+      gs_strfreev char **proc_cmdline_args = NULL;
+      char **strviter;
+
+      if (!g_file_load_contents (proc_cmdline_path, cancellable,
+                                 &proc_cmdline, &proc_cmdline_len,
+                                 NULL, error))
+        goto out;
+
+      proc_cmdline_args = g_strsplit (proc_cmdline, " ", -1);
+      for (strviter = proc_cmdline_args; strviter && *strviter; strviter++)
+        {
+          char *arg = *strviter;
+          g_strchomp (arg);
+          g_ptr_array_add (kargs, arg);
+          *strviter = NULL; /* transfer ownership */
+        }
+    }
+
+  if (opt_kernel_argv)
+    {
+      char **strviter;
+      for (strviter = opt_kernel_argv; strviter && *strviter; strviter++)
+        {
+          const char *arg = *strviter;
+          char *val = g_strdup (arg);
+          g_strchomp (val);
+          g_ptr_array_add (kargs, val);
+        }
+    }
+
+  g_ptr_array_add (kargs, NULL);
+
   if (!ostree_sysroot_deploy_one_tree (sysroot,
                                        opt_osname, revision, origin,
-                                       opt_kernel_argv, merge_deployment,
+                                       (char**)kargs->pdata, merge_deployment,
                                        &new_deployment,
                                        cancellable, error))
     goto out;
index 1f0b9c7e9e8b9751290e8afb25ce3c7d5e6e0c6c..395e281638e596532ee58eb52995dc5fe61c6ed9 100644 (file)
@@ -44,3 +44,11 @@ assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'option
 assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'options.*ANOTHERARG=ANOTHERVALUE'
 
 echo "ok deploy with --karg, but same config"
+
+ostree admin --sysroot=sysroot deploy --karg-proc-cmdline --os=testos testos:testos/buildmaster/x86_64-runtime
+# Here we're asserting that the *host* system has a root= kernel
+# argument.  I think it's unlikely that anyone doesn't have one, but
+# if this is not true for you, please file a bug!
+assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'options.*root=.'
+
+echo "ok deploy --karg-proc-cmdline"